<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // **目标：** 编写一个函数，接受一个数组作为参数，
    // 并返回数组中所有奇数的平均值（如果没有奇数则返回0）
    let arr = [11,2,33,4,55,6,77,8,]
    let sum = 0 
    let arr1 = []
    function anOddnumber(a){
      let c = 0 
      for(let i = 0; i < a.length+1; i++) {
        if(a[i] % 2 === 1 ){
          arr1.push(a[i])
          sum += a[i]
        } 
      }
          c = arr1.length
          return sum /c  ||  c
    }
    console.log(anOddnumber(arr));
    document.write();
  </script>
</body>
</html>